#!/usr/bin/perl -w # useful for syntax highlighting

package clreqd_modules;

use Fcntl;

sub diskhb_rawread {
my %ARGS=@_;
	#################################################################
	# Rather than calling the binary directly to get the raw 	#
	# block size we do it via the diskhb_blksize routine.		#
	#################################################################
	
	my $_res=diskhb_blksize(DEVNAME => $ARGS{DEVNAME});
	my @F=split(/\s+/,$_res);
	if($F[0] ne "OK") {
		return $_res;
	}
	my $blk_size=int($F[1]);
	my $offset=int($ARGS{OFFSET});
	my $length=int($ARGS{LENGTH});
	if($offset % $blk_size != 0) {
		return "ERROR Offset is not a multiple of device block size.";
	}
	if($length % $blk_size != 0) {
		return "ERROR Length is not a multiple of device block size.";
	}
	my $fd;
	sysopen($fd,$ARGS{DEVNAME},O_RDWR);
	if(! $fd) {
		return "ERROR Unable to open device '$ARGS{DEVNAME}': $!";
	}
	if(sysseek($fd,$offset,0) != $offset) {
		return "ERROR Unable to seek to offset '$offset' on '$ARGS{DEVNAME}'.";
	}
	my $d;
	if(sysread($fd,$d,$length) != $length) {
		return "ERROR Unable to read '$length' bytes of data from '$ARGS{DEVNAME}'.";
	}
	close($fd);
	return "OK " . unpack("H*",$d);
}
1;
